<template>
  <div style="z-index: 1; height: 500px; padding-top: 5px">
    <el-empty v-if="emptyVisible" :description="$t('common.empty_tip')" />
  </div>
</template>

<script>
import * as echarts from 'echarts'
import resize from '@/mixins/resize'
import { tomsVersionCount } from '@/api/statistic'

export default {
  name: 'LoginTimesChart',
  mixins: [resize],
  data() {
    return {
      series: [],
      chart: null,
      emptyVisible: false,
      legend: []
    }
  },
  mounted() {
    this.initData('Month', '6')
  },
  methods: {
    initData() {
      this.getOperatorActivity()
    },

    getOperatorActivity() {
      tomsVersionCount(this.$route.params.operatorId)
        .then((res) => {
          var isEmpty = true
          if (res) {
            console.log('tom版本', res)
            for (var i = 0; i < res.yaxisData.length; i++) {
              if (res.yaxisData[i] !== 0) {
                isEmpty = false
                break
              }
            }
          }
          if (isEmpty) {
            this.emptyVisible = true
          } else {
            this.initChart(res)
          }
        })
        .catch((e) => {
          this.$confirmError(e)
          this.emptyVisible = true
        })
    },
    initChart(data) {
      this.chart = echarts.init(this.$el)
      this.option = {
        // title: {
        //   text: this.$t('dashboard.top_10_merchants_and_active_merchants'),
        //   subtext: '纯属虚构'
        // },

        tooltip: {
          trigger: 'axis'
        },
        calculable: true,
        xAxis: [
          {
            type: 'category',
            data: data.xaxisData
          }
        ],
        yAxis: [
          {
            type: 'value'
          }
        ],
        series: [
          {
            // name: this.$t('data_center.appstore_new_app_version_count'),
            name: 'Devices',
            type: 'line',
            data: data.yaxisData
          }
        ]
      }
      this.chart.setOption(this.option, true)
    }
  }
}
</script>

<style>
</style>
